package com.yuexun.beilunpatient.ui.registration.presenter.impl;

import com.yuexun.beilunpatient.ui.registration.model.IRegistrationPayModel;
import com.yuexun.beilunpatient.ui.registration.presenter.IAppointmentPayPresenter;
import com.yuexun.beilunpatient.ui.registration.ui.view.IAppointmentPayView;

import org.kymjs.kjframe.ui.ViewInject;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by chenss on 2018/11/23.
 */
public class AppointmentPayPresenter implements IAppointmentPayPresenter {

    private IAppointmentPayView view;
    private IRegistrationPayModel model;

    //记录Log
//    private final Logger log = ProUtil.getLogger(LoginPresneter.class);

    public AppointmentPayPresenter(IRegistrationPayModel model, IAppointmentPayView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void generatePayOrder(Map<String, String> praise) {
        model.generatePayOrder(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<String>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("生成预约挂号支付订单号失败");
                    }

                    @Override
                    public void onNext(String s) {
                        view.generatePayOrder(s);
                    }
                });
    }
}
